package com.dvd.djc.gdjc001;

import org.hibernate.Transaction;

import com.dvd.dao.dvd.TDvd;
import com.dvd.dao.dvd.TDvdDAO;

public class GDJC001Model {

	public String cancelDvd(String DvdId)
	{
		
		TDvd dvd=this.searchDvdInfo(DvdId,null);
		if(dvd==null)
		{
			return null;
		}
		TDvdDAO dao=new TDvdDAO();		
		Transaction trans =dao.getSession().beginTransaction();
		dao.delete(dvd);
		trans.commit();
		dao.getSession().close();
		return dvd.getFDvdTitle();
	}
	
	public TDvd searchDvdInfo(String DvdId,String flag)
	{
		TDvdDAO dao=new TDvdDAO();	
		TDvd dvd=null;
		Transaction trans =dao.getSession().beginTransaction();
		if(flag==null)
		{
			dvd=dao.findById(DvdId);
		}
		else if(flag.equals("pre"))
		{
			dvd=dao.findPreById(DvdId);
		}
		else if(flag.equals("next"))
		{
			dvd=dao.findNextById(DvdId);
		}
		trans.commit();
		dao.getSession().close();
		return dvd;
	}
	
	
	/*test*/
	public static void main(String [] args)
	{
		GDJC001Model model = new GDJC001Model();
		TDvd dvd=null;
		try
		{
			dvd=model.searchDvdInfo("3", "next");
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		System.out.println(dvd.getFDvdId());
	}
	
	

}
